package com.scs.application.modules.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.scs.application.core.service.BaseServiceImpl;
import com.scs.application.core.utils.UserUtils;
import com.scs.application.modules.base.entity.SupplierDistributionItem;
import com.scs.application.modules.base.mapper.SupplierDistributionItemMapper;
import com.scs.application.modules.base.request.SupplierDistributionItemQueryRequest;
import com.scs.application.modules.base.service.SupplierDistributionItemService;
import com.scs.application.modules.base.vo.SupplierDistributionItemVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 运销商品授权 service 实现
 *
 */
@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class SupplierDistributionItemServiceImpl extends BaseServiceImpl<SupplierDistributionItemMapper, SupplierDistributionItem> implements SupplierDistributionItemService {

    @Override
    public List<SupplierDistributionItem> list(SupplierDistributionItemQueryRequest request) {
        List<SupplierDistributionItem> list = this.list(getQueryWrapper(request));
        return list;
    }

    @Override
    public IPage<SupplierDistributionItem> page(SupplierDistributionItemQueryRequest request) {
        IPage page = this.page(request.getPage(), getQueryWrapper(request));
        return page;
    }

    @Override
    public IPage<SupplierDistributionItemVO> pageAuthorizeMaterial(SupplierDistributionItemQueryRequest request) {
        request.setSupplierId(UserUtils.getSupplierId());
        IPage page = this.baseMapper.pageAuthorizeMaterial(request.getPage(), request);
        return page;
    }

    private QueryWrapper<SupplierDistributionItem> getQueryWrapper(SupplierDistributionItemQueryRequest request){
        return Wrappers.<SupplierDistributionItem>query()
                .orderByDesc("gmt_modified");
    }

}

